import Big from "big.js";
Big.PE = 40;
/**
 * 时间戳格式化
 * @param {String} 内容
 */ export function _formatDate(inputTime) {
    var date = new Date(parseInt((inputTime * 1000).toString()));
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? "0" + m : m;
    var d = date.getDate();
    d = d < 10 ? "0" + d : d;
    var h = date.getHours();
    h = h < 10 ? "0" + h : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? "0" + minute : minute;
    second = second < 10 ? "0" + second : second;
    return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
}
export function _formatDatea(inputTime) {
    var date = new Date(parseInt(inputTime * 1000));
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? "0" + m : m;
    var d = date.getDate();
    d = d < 10 ? "0" + d : d;
    var h = date.getHours();
    h = h < 10 ? "0" + h : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? "0" + minute : minute;
    second = second < 10 ? "0" + second : second;
    return y + "-" + m + "-" + d;
}
/**
 * @return {string}
 */ export function FormatDate(date_str, fmt) {
    date_str = typeof date_str === "string" ? date_str.replace(/-/g, "/").replace(".000", "") : date_str;
    var date = new Date(date_str);
    if (isNaN(date.getDate())) {
        return "";
    }
    if (!fmt) {
        fmt = "yyyy-MM-dd";
    }
    var o = {
        "M+": date.getMonth() + 1,
        //月份
        "d+": date.getDate(),
        //日
        "h+": date.getHours(),
        //小时
        "m+": date.getMinutes(),
        //分
        "s+": date.getSeconds(),
        //秒
        "q+": Math.floor((date.getMonth() + 3) / 3),
        //季度
        S: date.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for(var k in o)if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return fmt;
}
/**
 * @return {string}
 */ export function FormatDatea(date_str, fmt) {
    date_str = typeof date_str === "string" ? date_str.replace(/-/g, "/").replace(".000", "") : date_str;
    var date = new Date(date_str);
    if (isNaN(date.getDate())) {
        return "";
    }
    if (!fmt) {
        fmt = "yyyy/MM/dd";
    }
    var o = {
        "M+": date.getMonth() + 1,
        //月份
        "d+": date.getDate(),
        //日
        "h+": date.getHours(),
        //小时
        "m+": date.getMinutes(),
        //分
        "s+": date.getSeconds(),
        //秒
        "q+": Math.floor((date.getMonth() + 3) / 3),
        //季度
        S: date.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for(var k in o)if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return fmt;
}
export function FormatDateb(date_str, fmt) {
    date_str = typeof date_str === "string" ? date_str.replace(/-/g, "/").replace(".000", "") : date_str;
    var date = new Date(date_str);
    if (isNaN(date.getDate())) {
        return "";
    }
    if (!fmt) {
        fmt = "MM/dd";
    }
    var o = {
        "M+": date.getMonth() + 1,
        //月份
        "d+": date.getDate(),
        //日
        "h+": date.getHours(),
        //小时
        "m+": date.getMinutes(),
        //分
        "s+": date.getSeconds(),
        //秒
        "q+": Math.floor((date.getMonth() + 3) / 3),
        //季度
        S: date.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for(var k in o)if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return fmt;
}
/**
 * 处理科学计数的问题
 * @param num
 * @returns {string|number}
 */ export function toNonExponential(num) {
    if (!num) {
        return 0;
    }
    num = parseFloat(num);
    if (isNaN(num)) {
        return 0;
    }
    var m = num.toExponential().match(/\d(?:\.(\d*))?e([+-]\d+)/);
    return num.toFixed(Math.max(0, (m[1] || "").length - m[2]));
}
/**
 * 保留2位小数
 * @param num
 * @returns {string|number}
 */ export function toFixed(num) {
    if (!num) {
        return 0;
    }
    num = parseFloat(num);
    if (isNaN(num)) {
        return 0;
    }
    var m = num.toExponential().match(/\d(?:\.(\d*))?e([+-]\d+)/);
    return num.toFixed(2);
}
/**
 * 保留4位小数
 * @param num
 * @returns {string|number}
 */ export function toFixed4(num) {
    if (!num) {
        return 0;
    }
    num = parseFloat(num);
    if (isNaN(num)) {
        return 0;
    }
    var m = num.toExponential().match(/\d(?:\.(\d*))?e([+-]\d+)/);
    return num.toFixed(4);
}
/**
 * 处理富文本图片限制
 * @param num
 * @returns {string|number}
 */ export function richtextlimit(attr) {
    if (attr) {
        var regex = new RegExp("<img", "gi");
        var richtext = attr.replace(regex, "<img height='auto' style=\"max-width: 100%;\"");
        return richtext;
    }
}
/**
 * 电话号码中间用*代替
 * @param cellValue
 * @returns {string|*}
 */ export function phoneMethod(cellValue) {
    if (Number(cellValue) && String(cellValue).length === 11) {
        var mobile = String(cellValue);
        var reg = /^(\d{3})\d{4}(\d{4})$/;
        return mobile.replace(reg, "$1****$2");
    } else if (!cellValue) {
        return "";
    } else {
        return cellValue;
    }
}
/**
 * 千分符号
 */ export function numFormat(num) {
    if (num) {
        var res = num.toString().replace(/\d+/, function(n) {
            // 先提取整数部分
            return n.replace(/(\d)(?=(\d{3})+$)/g, function($1) {
                return $1 + ",";
            });
        });
        return res;
    } else {
        return "0";
    }
}
/**
 * 数字单位化
 */ export function nFormatter(num) {
    var si = [
        {
            value: 1,
            symbol: ""
        },
        {
            value: 1e3,
            symbol: "K"
        },
        {
            value: 1e6,
            symbol: "M"
        },
        {
            value: 1e9,
            symbol: "G"
        },
        {
            value: 1e12,
            symbol: "T"
        },
        {
            value: 1e15,
            symbol: "P"
        },
        {
            value: 1e18,
            symbol: "E"
        }
    ];
    var rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
    var i;
    for(i = si.length - 1; i > 0; i--){
        if (num >= si[i].value) {
            break;
        }
    }
    return (num / si[i].value).toFixed(2).replace(rx, "$1") + si[i].symbol;
}
export function stringMethod(string) {
    var maxLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 16;
    if (string === "null") return "";
    if (string) {
        if (string.length > maxLength) {
            var pro = Math.floor(5 / 8 * maxLength);
            var ex = maxLength - pro;
            var aaa = String(string);
            var a = aaa.substring(0, pro);
            var b = aaa.substring(string.length - ex, string.length);
            return a + "..." + b;
        } else if (!string) {
            return "";
        } else {
            return string;
        }
    } else {
        return string;
    }
}
/** wei 转币 */ var toEther = function(wei, digits) {
    try {
        if (!wei) return "-";
        return new Big(wei).div("1e".concat(digits)).toString();
    } catch (e) {
        return "-";
    }
};
/** 币转 wei */ var toWei = function(ether, digits) {
    try {
        if (!ether) return "-";
        return new Big(ether).mul("1e".concat(digits)).toString();
    } catch (e) {
        return "-";
    }
};
/** wei 转币 */ var toFormatEther = function(wei, digits) {
    try {
        if (!wei || wei == "0") return "-";
        return numFormat(new Big(wei).div("1e".concat(digits)).round(6).toString());
    } catch (e) {
        return "-";
    }
};
/** 转 USD */ var toFormatUSD = function(usd, digits) {
    try {
        if (!usd || usd == "0") return "-";
        return numFormat(new Big(usd).div("1e".concat(digits)).round(2).toString());
    } catch (e) {
        return "-";
    }
};
export default {
    stringMethod: stringMethod,
    nFormatter: nFormatter,
    numFormat: numFormat,
    phoneMethod: phoneMethod,
    richtextlimit: richtextlimit,
    toFixed4: toFixed4,
    _formatDate: _formatDate,
    _formatDatea: _formatDatea,
    FormatDate: FormatDate,
    FormatDatea: FormatDatea,
    FormatDateb: FormatDateb,
    toNonExponential: toNonExponential,
    toFixed: toFixed,
    toEther: toEther,
    toWei: toWei,
    toFormatEther: toFormatEther,
    toFormatUSD: toFormatUSD
};

 //# sourceMappingURL=filters.js.map